package com.zjy.software.day16;

import java.io.File;
import java.io.IOException;

public class FileDemo {
    public static void main(String[] args) throws IOException {
        // 获取文件分隔符
        System.out.println("File.separator = " + File.separator);

        //获取路径的分隔符
        System.out.println("File.pathSeparator = " + File.pathSeparator);

        File file=new File("testFile.txt");
        boolean newFile = file.createNewFile();
        System.out.println("newFile = " + newFile);

        file=new File("testFolder");
        file.mkdir();
        System.out.println("file.isDirectory() = " + file.isDirectory());

        File tmpFile=new File("testFile.txt");
        tmpFile.renameTo(new File("newfile.txt"));
        System.out.println("tmpFile.isDirectory() = " + tmpFile.isDirectory());
        System.out.println("tmpFile.isFile() = " + tmpFile.isFile());

        File file1=new File("newfile1.txt");
        System.out.println("file1.isFile() = " + file1.isFile());

        //获取绝对路径
        System.out.println("file1.getAbsoluteFile() = " + file1.getAbsoluteFile());
        System.out.println("file1.getPath() = " + file1.getPath());

        System.out.println("file1.length() = " + file1.length());

        File folder=new File("testFolder");

        //获取文件夹下的所有文件
        File[] files = folder.listFiles();
        for (File file2 : files) {
            if(file2.isFile()){
                System.out.println("我是一个文件file2.getName() = " + file2.getName());
            }else{
                System.out.println("我是一个文件夹file2.getName() = " + file2.getName());
            }
            System.out.println(file2);
        }

        String[] list = folder.list();
        for (String s : list) {
            System.out.println("s = " + s);
        }

        boolean isDelete = file1.delete();
        System.out.println("isDelete = " + isDelete);

    }
}
